package dao_redis

import (
	"context"
	"fmt"
	"github.com/go-jose/go-jose/v4/json"
	"onerk4/zk2/common/global"
	"onerk4/zk2/common/model"
	"time"
)

func SetSms(mobile, source, code string) error {
	key := fmt.Sprintf("%s:%s", source, mobile)
	err := global.Rdb.Set(context.Background(), key, code, time.Minute*5).Err()
	if err != nil {
		return err
	}
	return nil
}

func GetSms(mobile, source string) (string, error) {
	key := fmt.Sprintf("%s:%s", source, mobile)
	result, err := global.Rdb.Get(context.Background(), key).Result()
	if err != nil {
		return "", err
	}
	return result, nil
}

func SetSearchEnterpriseData(data []*model.EbStoreProduct) error {
	key := "SetSearchEnterpriseData"
	marshal, err := json.Marshal(data)
	if err != nil {
		return err
	}
	err = global.Rdb.Set(context.Background(), key, marshal, time.Hour*2).Err()
	if err != nil {
		return err
	}
	return nil
}
